package com.lphj.datainterface.handle;

import com.lphj.datainterface.entity.CumOrderDtl;
import com.lphj.datainterface.entity.CumOrderList;
import com.lphj.datainterface.entity.Goods;
import com.lphj.datainterface.entity.TGoods;
import com.lphj.datainterface.service.CumOrderListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class CumOrderListHandle {

    @Autowired
    CumOrderListService cumOrderListService;

    /**
     * 插入订单池
     * @param cumOrderDtl 订单明细
     * @param goods 商品
     * @param cumNO 客户编码
     * @param storeNO 公司编码
     * @param orderDate 订单日期
     * @param deliveryDate 发货日期
     * @return
     */
    int insertCumOrderList(CumOrderDtl cumOrderDtl, TGoods goods, String cumNO, String storeNO, Date orderDate, Date deliveryDate) {
        CumOrderList cumOrderList = null;
        int countList = 0;
        if(cumOrderDtl != null) {
            cumOrderList = new CumOrderList();
            cumOrderList.setPaperNO(cumOrderDtl.getPaperNO());
            cumOrderList.setStoreNO(storeNO);
            cumOrderList.setCumNO(cumNO);
            cumOrderList.setItem(cumOrderDtl.getItem());
            cumOrderList.setGoodsID(goods.getGoodsID());
            cumOrderList.setOrdUnit(goods.getUnit());
            cumOrderList.setUnit(goods.getUnit());
            cumOrderList.setFactor(1.00);
            cumOrderList.setOrdQty(cumOrderDtl.getOrdQty());
            cumOrderList.setQty(cumOrderDtl.getQty());
            cumOrderList.setSalePrice(cumOrderDtl.getSalePrice());
            //是否已生成采购订单 0=否 10=待生成 100=已生成 200=特殊采购
            cumOrderList.setTag(10);
            cumOrderList.setNote("");
            cumOrderList.setOrderType1("");
            cumOrderList.setOrderDate(orderDate);
            cumOrderList.setDeliveryDate(deliveryDate);
            cumOrderList.setLastUpdateUser("lphj");
            cumOrderList.setLastUpdateTime(new Date());
            countList += cumOrderListService.addCumOrderList(cumOrderList);
        }
        return countList;
    }
}
